package com.xmb.wechat.delegate;

import android.app.Activity;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.nil.sdk.utils.DateUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.application.WechatStartApplication;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.bean.AliPayBillBean;
import com.xmb.wechat.util.PicLoadUtils;

import java.util.ArrayList;
import java.util.Date;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/25 16:20
 */
public class AlipayBillDelegate extends BaseRecyclerViewManager {

    public AlipayBillDelegate(Activity activity) {
        super(activity);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<AliPayBillBean, BaseViewHolder>(R.layout.item_alipay_bill, new ArrayList<>()) {
            @Override
            protected void convert(BaseViewHolder helper, AliPayBillBean item) {
                //头像
                PicLoadUtils.setupRoundPicIntoImageView(item.getIconSourceType(), item.getIconUrl(), helper.getView(R.id.iv_icon));
                //标题
                helper.setText(R.id.tv_title, TextUtils.isEmpty(item.getTitle()) ? "" : item.getTitle());
                //时间
                helper.setText(R.id.tv_time, DateUtils.getStringByFormat(new Date(item.getTradeTime()), "yyyy-MM-dd HH:mm"));
                //金额
                if (item.isExpend()) {
                    helper.setText(R.id.tv_money, TextUtils.isEmpty(item.getMoney()) ? "" : "-" + item.getMoney());
                    helper.setTextColor(R.id.tv_money, context.getResources().getColor(R.color.color_3));
                } else {
                    helper.setText(R.id.tv_money, TextUtils.isEmpty(item.getMoney()) ? "" : "+" + item.getMoney());
                    helper.setTextColor(R.id.tv_money, context.getResources().getColor(R.color.red_orange_3));
                }
                //状态
                switch (item.getTradeState()) {
                    case 0:
                        helper.setTextColor(R.id.tv_state, context.getResources().getColor(R.color.red_orange_4));
                        break;
                    default:
                        helper.setTextColor(R.id.tv_state, context.getResources().getColor(R.color.color_9));
                        break;
                }
                helper.setText(R.id.tv_state, TextUtils.isEmpty(item.getTradeStateValue()) ? "" : item.getTradeStateValue());
                //删除
                helper.getView(R.id.iv_delete).setOnClickListener(v -> {
                    WechatStartApplication.getBoxStore().boxFor(AliPayBillBean.class).remove(item);
                    mData.remove(item);
                    notifyDataSetChanged();
                });
            }
        };

    }
}
